﻿////获取随机数，chance越大显示的几率越大。
//function mbsgg(url, chance) {
//    this.url = url;
//    this.chance = chance;
//}

//var da, dalen, chance_limit, random_sel_num
//da = new Array();
//da[0] = new mbsgg("粉色", 0)
//da[1] = new mbsgg("黑色", 0)
//da[2] = new mbsgg("红色", 0)
//da[3] = new mbsgg("蓝色", 0)
//da[4] = new mbsgg("深灰色", 0)
//da[5] = new mbsgg("绿色", 0)
//da[6] = new mbsgg("深棕色", 100)
//var dalen = da.length;
num_all_chance = 0;
for (i = 0; i < dalen; i++) {
    num_all_chance += da[i].chance;
}

function random_da() {
    chance_limit = 0;
    random_sel_num = Math.round((num_all_chance - 1) * Math.random()) + 1;
    for (i = 0; i < dalen; i++) {
        chance_limit += da[i].chance;
		//alert(chance_limit);
        if (random_sel_num <= chance_limit) {
            //alert(random_sel_num+"显示第"+(i+1)+"个广告");
            return i + 1;
            break;
        }
    }
}

//获取屏数量并初始化第一屏
//var cookiecoun = parseInt(Math.random() * 5 + 1); //从第一屏随机数(共5屏)
//var cookiecoun = 7;
var cookiecoun = random_da(); //获取权重随机数(共5屏)

    function tips_pop() {
        var MsgPop = document.getElementById("floatad-winpop" + tidvalue);
        var popH = parseInt(MsgPop.style.height);
        if (popH == 0) {
            MsgPop.style.display = "block";
            show = setInterval("changeH('up')", 2);
        }
        else {
            hide = setInterval("changeH('down')", 2);
        }
    }
	var kbox_height = 343;
    function changeH(str) {
        var MsgPop = document.getElementById("floatad-winpop" + tidvalue);
        var popH = parseInt(MsgPop.style.height);
        if (str == "up") {
            if (cookiecoun == 4) {
                kbox_height = 340;
            } 
			else if (cookiecoun == 2) {
                kbox_height = 285;
            }
			else if (cookiecoun == 5) {
                kbox_height = 326;
            }
			else if (cookiecoun == 6) {
                kbox_height = 315;
            }
            else if (cookiecoun == 7) {
                kbox_height = 315;
            }
            else {
                kbox_height = 290;
            }
			if (popH <= kbox_height) {
                MsgPop.style.height = (popH + 4).toString() + "px";
            }
            else {
                clearInterval(show);
            }
        }
        if (str == "down") {
            if (popH >= 4) {
                MsgPop.style.height = (popH - 4).toString() + "px";
            }
            else {
                clearInterval(hide);
                MsgPop.style.display = "none";
            }
        }
    }
 
    function setTab(name, cursel, n) {
        for (i = 1; i <= n; i++) {
            var menu = document.getElementById(name + i);
            var con = document.getElementById("con_" + name + "_" + i);
            menu.className = i == cursel ? "hover" : "";
            con.style.display = i == cursel ? "block" : "none";
        }
    }

    var nameid = cookiecoun; //获得到上面的屏幕cookiecoun值
    if (nameid == 1 || nameid == "") {
        nametxt = "one"; //第1屏
    } else if (nameid == 2) {
        nametxt = "two"; //第2屏
    } else if (nameid == 3) {
        nametxt = "three"; //第3屏
    } else if (nameid == 4) {
        nametxt = "four"; //第4屏
    } else if (nameid == 5) {
        nametxt = "five"; //第5屏
    } else if (nameid == 6) {
        nametxt = "six"; //第6屏
    } else if (nameid == 7) {
        nametxt = "seven"; //第7屏
    } else if (nameid == 8) {
        nametxt = "eight"; //第8屏
    } else if (nameid == 9) {
        nametxt = "nine"; //第9屏
    } else {
        nametxt = "ten"; //第10屏
    }

    var CurPopPub = 1;
    var PopPubHandle = null;
    function SetPopPubhandle(name) {
        setTab(name, CurPopPub, 4);
        PopPubHandle = setInterval(function () { setTab(name, CurPopPub, 4); CurPopPub++; if (CurPopPub == 5) CurPopPub = 1; }, 3000);
    }
    $(function () {
        $("[id^='" + nametxt + "']").each(function (i) {
            $(this).mouseover(function () { if (PopPubHandle) clearInterval(PopPubHandle); CurPopPub = parseInt(i) + 1; setTab(nametxt, CurPopPub, 4); }).mouseout(function () { SetPopPubhandle(nametxt); });
        });
        $("[id^='con_'" + nametxt + "'_']").each(function () {
            $(this).mouseover(function () { if (PopPubHandle) clearInterval(PopPubHandle); }).mouseout(function () { SetPopPubhandle(nametxt); });
        });

        SetPopPubhandle(nametxt);
    });

    $(document).ready(function () {
        setTimeout(function () {
            tips_pop(tidvalue = cookiecoun);
        }, 2000); //右下框弹出广告函数
    });
